<?php
declare (strict_types = 1);

namespace app\middleware;

use think\facade\Cache;
use think\Response;

class Auth
{
    /**
     * 处理请求
     *
     * @param \think\Request $request
     * @param \Closure       $next
     * @return Response
     */
    public function handle(\think\Request $request, \Closure $next): Response
    {
        //
        $token = trim(str_replace("Bearer ", "", $request->header('Authorization')));
        $cache = Cache::get($token);
        if($cache==null){
            return error([],3001,'登录已失效');
        }
        $request->cache = $cache;
        return $next($request,$cache);

    }
}
